package com.ofa.dao;

import java.util.List;

import org.springframework.stereotype.Component;

import com.ofa.base.HibernateDAOImpl;
import com.ofa.base.Pagination;
import com.ofa.entity.Role;


@Component(value="roleDao")
public class RoleDao extends HibernateDAOImpl<Role> {

	public void save(Role Role) {
		getHibernateTemplate().save(Role);
	}

	public void update(Role Role) {
		getHibernateTemplate().update(Role);
	}
	
	public Pagination<Role> queryRoles(Role Role, int firstResult, int maxResults){
		String hql = "select r from Role r where 1=1 ";
		
		List<Role> list = this.getSession()
				.createQuery(hql)
				.setFirstResult(firstResult)
				.setMaxResults(maxResults)
				.list();

		String countHql = "select count(r.id) from Role r where 1=1 ";
		int total = ((Long)(this.getSession().createQuery(countHql).uniqueResult())).intValue();
		
		Pagination<Role> pagination = new Pagination<Role>();
		pagination.setData(list);
		pagination.setTotal(total);
		return pagination;
	}
	
	
	
}
